package org.jeecg.modules.messages.service.impl;

import org.jeecg.modules.messages.entity.BlogMessages;
import org.jeecg.modules.messages.mapper.BlogMessagesMapper;
import org.jeecg.modules.messages.service.BlogMessagesService;
import org.jeecg.modules.messageReplies.entity.BlogMessageReplies;
import org.jeecg.modules.messageReplies.service.BlogMessageRepliesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.ArrayList;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: blog_messages
 * @Author: jeecg-boot
 * @Date:   2025-06-30
 * @Version: V1.0
 */
@Service
@Slf4j
public class BlogMessagesServiceImpl extends ServiceImpl<BlogMessagesMapper, BlogMessages> implements BlogMessagesService {

    @Autowired
    private BlogMessageRepliesService blogMessageRepliesService;

    @Override
    public List<BlogMessageReplies> getRepliesByMessageId(String messageId) {
        try {
            QueryWrapper<BlogMessageReplies> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("message_id", messageId)
                    .eq("status", 1) // 只查询已审核的回复
                    .orderByAsc("create_time");
            return blogMessageRepliesService.list(queryWrapper);
        } catch (Exception e) {
            log.error("查询回复时发生错误", e);
            return new ArrayList<>();
        }
    }
}
